package zhtt.derby.mapper;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import zhtt.derby.entity.User;

@Mapper
public interface  UserMapper {

    @Update("create table if not exists ZHTT_USER (id int not null primary key auto_increment, name varchar(100),sex varchar(1),age NUMBER(3),phone VARCHAR(11),email VARCHAR(100),create_time DATE)")
    void create() throws Exception;

    @Select("select count(1) from zhtt_user")
    Integer count() throws Exception;

    @Select("select * from zhtt_user")
    List<User> selectAll() throws Exception;

    @Select("select * from zhtt_user order by id asc {limit ${limit} offset ${offset}}")
    List<User> selectSeveral(@Param("limit")int limit, @Param("offset")int offset) throws Exception;

    @Insert("insert into zhtt_user(id,name,age) values(#{o.id}, #{o.name}, #{o.age})")
    void insert(@Param("o")User obj) throws Exception;

    @Delete("delete from zhtt_user where id in <foreach item='item' index='index' collection='ids' open='(' separator=',' close=')'>#{item}</foreach>")
    void delete(@Param("ids")List<String> ids) throws Exception;

    @Update("update zhtt_user set name = #{o.name}, age = #{o.age} where id = #{o.id}")
    void update(@Param("o")User obj) throws Exception;
    
}
